(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:PeriodstlCtrl
     * @description
     * # PeriodstlCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('PeriodstlCtrl', PeriodstlCtrl);

    PeriodstlCtrl.$inject = ['$scope', 'dataService', 'helper', 'dhfprinterService', '$timeout', '$interval', '$rootScope', '$state', 'moment'];

    function PeriodstlCtrl($scope, dataService, helper, dhfprinterService, $timeout, $interval, $rootScope, $state, moment) {
        $scope.listAction = function() {

            $scope.store_id = $rootScope.store_id

            //查询所有的桌子的人数，然后组成数组排列
            $scope.getlist();
        }

        $scope.getlist = function() {

            dataService.periodstlGet({ schema_id: 0 }).then(function(re1) {
                if (re1) {
                    $scope.periocd = re1;
                    $scope.periocd = _.sortBy($scope.periocd, 'period_stl_id');
                }
                console.error("re1", re1, $scope.periocd);
            });
        }

        $scope.saveData = function() {

            async.map($scope.periocd, function(data, callback) {
                if (data) {
                    var iad = { "period_stl_id": data.period_stl_id, status: data.status }
                    dataService.periodstlUpdate(iad).then(function(r) {
                        callback(null);
                    })
                } else {
                    callback(null);
                }
            }, function(e, r) {
                helper.myAlert("success", null, null, function() {
                    $state.go("periodstl.list");
                });
            });
        }
    }
})();